package com.cskaoyan.controller.admin.usermanage;

import com.cskaoyan.anno.ValidAnno;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo;
import com.cskaoyan.service.admin.usermanage.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author MoJunXiang
 * @since 2022/09/07 09:29
 */
@RestController
@RequestMapping("admin")
public class UserManageController {

    @Autowired
    UserManageService userManageService;

    /**
     * @function_name userlist
     *
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @idea 返回**所有**用户信息
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/07 23:53
     */
    @RequestMapping("user/list")
    public BaseRespVo<UsesrManageListVo> userlist(Integer page, Integer limit, String username, String mobile, String sort, String order) {
        UsesrManageListVo usesrManageListVo = userManageService.userlist(page, limit, username, mobile, sort, order);

        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(usesrManageListVo);

        return vo;
    }


    /**
     * @function_name detail
     * @param id
     * @idea 根据传入的 *id* 在 **market_user表** 中找到对应 *id* 的数据并返回它
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.MarketUser>
     * @author MoJunXiang
     * @since 2022/09/13 9:39
     */
    @RequestMapping("user/detail")
    public BaseRespVo<MarketUser> detail(Integer id) {
        MarketUser user = userManageService.detail(id);

        return BaseRespVo.ok(user);
    }


    @PostMapping("user/update")
    public BaseRespVo update(@RequestBody MarketUser user) throws Exception {
        userManageService.update(user);

        return BaseRespVo.ok(1);
    }


    /**
     * @function_name addresslist
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @idea 若 *name* ， *userId* 为空，则返回 **所有用户** 的 **所有地址** ；否则则 模糊查询  *name* ， 精确查询  *userId* ，返回对应的 **地址**
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/07 23:53
     */
    @RequestMapping("address/list")
    public BaseRespVo<UsesrManageListVo> addresslist(Integer page, Integer limit, String name, Integer userId, String sort, String order) {
        UsesrManageListVo listVo = userManageService.addresslist(page, limit, name, userId, sort, order);

        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(listVo);

        return vo;
    }



    /**
     * @function_name collectlist
     * @param page
     * @param limit
     * @param userId
     * @param valueId
     * @param sort
     * @param order
     * @idea 若 *userId* 与 *valueId* 为空，则返回**会员**的所有**收藏**；否则，返回 **market_collect表** 里对应 *userId* 和 *valueId* 的数据
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/13 10:17
     */
    @RequestMapping("/collect/list")
    public BaseRespVo<UsesrManageListVo> collectlist(Integer page, Integer limit, Integer userId, Integer valueId, String sort, String order) {
        UsesrManageListVo listVo = userManageService.collectlist(page, limit, userId, valueId, sort, order);


        // 返回值
        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(listVo);

        return vo;
    }



    /**
     * @function_name footprintlist
     * @param page
     * @param limit
     * @param userId
     * @param goodsId
     * @param sort
     * @param order
     * @idea 若 *userId* 与 *goodsId* 为空，则返回**会员**的所有**足迹**；否则，返回 **market_footprint表** 里对应 *userId* 和 *goodsId* 的数据
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/13 10:24
     */
    @RequestMapping("/footprint/list")
    public BaseRespVo<UsesrManageListVo> footprintlist(Integer page, Integer limit, Integer userId, Integer goodsId, String sort, String order) {
        UsesrManageListVo listVo = userManageService.footprintlist(page, limit, userId, goodsId, sort, order);

        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(listVo);

        return vo;
    }


    /**
     * @function_name historylist
     * @param page
     * @param limit
     * @param userId
     * @param keyword
     * @param sort
     * @param order
     * @idea 若 *userId* 与 *keyword* 为空，则返回**会员**的所有**搜索历史**；否则，返回 **market_search_history表** 里对应 *userId* 和 *keyword* 的数据返回所有**会员**的所有**搜索历史**
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/13 10:30
     */
    @RequestMapping("/history/list")
    public BaseRespVo<UsesrManageListVo> historylist(Integer page, Integer limit, Integer userId, String keyword, String sort, String order) {
        UsesrManageListVo listVo = userManageService.historylist(page, limit, userId, keyword, sort, order);

        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(listVo);

        return vo;
    }



    /**
     * @function_name feedbacklist
     * @param page
     * @param limit
     * @param username
     * @param sort
     * @param order
     * @param id
     * @idea 若 *id* 与 *username* 为空，则返回**会员**的所有**反馈**；否则，返回 **market_feedback表** 里对应 *id* 和 *username* 的数据返回
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.usermanage.UsesrManageListVo>
     * @author MoJunXiang
     * @since 2022/09/13 10:57
     */
    @RequestMapping("/feedback/list")
    public BaseRespVo<UsesrManageListVo> feedbacklist(Integer page, Integer limit, String username, String sort, String order, Integer id) {
        UsesrManageListVo listVo = userManageService.feedbacklist(page, limit, username, sort, order, id);

        // 返回值
        BaseRespVo<UsesrManageListVo> vo = new BaseRespVo<>();
        vo.setErrno(0);
        vo.setErrmsg("成功");
        vo.setData(listVo);

        return vo;
    }
}
